import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto } from './dto/update-role.dto';
import { Result } from 'src/utils/Result';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { SelectRoleDTO } from './dto/select-role.dto';

@ApiTags('角色管理')
@Controller('role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}
  @ApiOperation({ description: '新增角色' })
  @Post('/create')
  async create(@Body() createRoleDto: CreateRoleDto) {
    const result = await this.roleService.create(createRoleDto)
    return Result.success(result)
  }
  @ApiOperation({ description: '获取所有角色列表' })
  @Post('/list')
  async findAll(@Body() data: SelectRoleDTO): Promise<Result> {
    const result = await this.roleService.findAll(data);
    return Result.success(result)
  }
  @ApiOperation({ description: '获取角色详情' })
  @Get(':id')
  async findOne(@Param('id') id: string) {
    const result = await this.roleService.findOne(+id);
    return Result.success(result)
  }
  @ApiOperation({ description: '修改角色信息' })
  @Post('update:id')
  async update(@Param('id') id: string, @Body() updateRoleDto: UpdateRoleDto) {
    const result = await this.roleService.update(+id, updateRoleDto);
    return Result.success(result)
  }
  @ApiOperation({ description: '删除角色信息' })
  @Post('del:id')
  async remove(@Param('id') id: string) {
    const result = await this.roleService.remove(+id);
    return Result.success(result)
  }
}
